#![allow(dead_code)]
#![allow(unused_unsafe,dead_code)]


use std::collections::HashMap;
use mlua::Result;

pub fn set_error(table:&mut HashMap<String,String>, err:impl ToString){
    table.insert("error".to_string(),err.to_string());
}
pub fn return_error(mut table:HashMap<String,String>,err:impl ToString)->Result<HashMap<String,String>>{
    table.insert("error".to_string(),"true".to_string());
    table.insert("error_msg".to_string(),err.to_string());
    Ok(table)
}

pub fn to_static_str(buf:String)->&'static str{
    unsafe {
        Box::leak(Box::from(buf.as_str()))
    }
}

pub trait AsStr{
    fn as_str(self)->&'static str;
}
impl AsStr for Vec<u8>{
    fn as_str(self)->&'static str{
        unsafe {
            let buf:&'static [u8] = Box::leak(Box::new(self));
            std::str::from_utf8_unchecked(buf)
        }
    }
}